Blood pressure and pulse readings taken morning and evening with an Omron blood pressure cuff. Also collect binary factors: work, cycling and alcohol. Attempt to correlate blood pressure and pulse with factors.
Readings start on Feb 8, 2019. Alcohol was abstained from between Jan 1, 2019 and Apr 18, 2019, a period of 109 days.
Read and preprocess latest blood-pressure file. Join with a file containing factors (work, cycling and alcohol).
library(lubridate)
b <- read.csv(file="bp.csv", header=TRUE, sep=",")
b$date <- as.Date(b$date)
f <- read.csv(file="factors.csv", header=TRUE, sep=",")
f$date <- as.Date(f$date)
bp <- merge(b, f, by.x = "date", by.y = "date", all.x = TRUE)
bp[is.na(bp)] <- 0
bp$datetime <- as_datetime(paste(bp$date, bp$time))
mp <- c(min(bp$dia), max(bp$sys))
cdia <- rgb(0,0,1,1/4)
csys <- rgb(1,0,0,1/4)
cpul <- rgb(0,1,0,1/4)
A function to plot blood pressure histograms:
plot.blood.pressure <- function(bp, title) {
b <- seq(mp[1], mp[2], by=(mp[2] - mp[1]) / 20)
hdia <- hist(bp$dia, breaks=b, plot=F)
hsys <- hist(bp$sys, breaks=b, plot=F)
mc <- c(0, max(c(hsys$counts, hdia$counts)))
plot(hdia, col=cdia, xlim=mp, ylim=mc, main = paste(title, " (", min(bp$date), " to ", max(bp$date), ")", sep=""), xlab = "mmHg")
plot(hsys, col=csys, xlim=mp, ylim=mc, add=T)
mdia <- mean(bp$dia)
msys <- mean(bp$sys)
abline(v=c(msys, mdia), col=c("red","blue"))
legend("topright", bty="n", legend=c(paste("sys: ", format(msys, digits=2)), paste("dia: ", format(mdia, digits=2))))
}
Plot systolic and diastolic pressures for all data points.
plot.blood.pressure(bp, "Overall")
Over the last four weeks:
plot.blood.pressure(bp[max(bp$date) - bp$date <= 28,], "Recently")
am <- hour(bp$datetime) < 12
plot.blood.pressure(bp[am,], "Morning")
pm <- hour(bp$datetime) >= 12
plot.blood.pressure(bp[pm,], "Evening")
plot.blood.pressure(bp[bp$work == 1,], "Work")
plot.blood.pressure(bp[bp$work == 0,], "Days Off")
Systolic and diastolic blood pressure over time.
movavg <- function(x, n=14){
filter(x,rep(1/n,n), sides=2)
}
plot.dates <- function(bp, var, col, yl="mmHg", ma=T) {
cs <- c("green", "blue")
dates <- bp$datetime
points <- bp[,var]
am <- hour(bp$datetime) < 12
pm <- !am
plot(dates[am], points[am], xlab="Date", ylab=yl, main=var, col=cs[1])
abline(v=dates[bp$work == 1], col="lightgray")
abline(v=dates[pm & (bp$alcohol == 1)], col="red")
abline(v=dates[pm & (bp$cycle == 1)], col="green")
if (ma) {
lines(dates[am], movavg(points[am]), col=cs[1])
lines(dates[pm], movavg(points[pm]), col=cs[2])
}
sd <- lm(points~dates)
abline(sd, col=col)
points(dates[am], points[am], col=cs[1])
points(dates[pm], points[pm], col=cs[2])
legend("bottomright", bty="n", legend=paste("r^2: ", format(summary(sd)$r.squared, digits=2)))
legend("bottomleft", bty="n", legend=c("am", "pm"), text.col = cs, pt.bg=cs)
}
plot.dates(bp, "sys", "red")
plot.dates(bp, "dia", "blue")
plot(bp$dia, bp$sys, xlab = "Diastolic", ylab="Systolic")
msd <- lm(bp$sys~bp$dia)
abline(msd)
legend("bottomright", bty="n", legend=paste("r^2: ", format(summary(msd)$r.squared, digits=2)))
plot.pulse <- function(bp, c, title) {
hpul <- hist(bp$pulse, plot=F)
plot(hpul, col=c, main = title, xlab = "bpm")
m <- mean(bp$pulse)
abline(v=m, col=c)
legend("topright", bty="n", legend=paste("av: ", format(m, digits=2)))
}
plot.pulse(bp, cpul, "Overall")
Working days and days off.
plot.pulse(bp[am & bp$work==1 & bp$alcohol==0,], cpul, "Morning (work)")
plot.pulse(bp[am & bp$work==0 & bp$alcohol==0,], cpul, "Morning (off)")
Evening of working days and days off.
plot.pulse(bp[am & bp$work==1 & bp$alcohol==0,], cpul, "Evening (work)")
plot.pulse(bp[pm & bp$work==0 & bp$alcohol==0,], cpul, "Evening (off)")
plot.dates(bp, "pulse", "green", "bpm")
The initial period without alcohol (between Jan 1 and Apr 18, 2019). This coincided with work.
plot.blood.pressure(bp[bp$datetime < "2019-04-18",], "Alcohol-free")
plot.dates(bp[bp$datetime < "2019-04-18",], "sys", "red")
plot.dates(bp[bp$datetime < "2019-04-18",], "dia", "blue")
plot.dates(bp[bp$datetime < "2019-04-18",], "pulse", "green", "bpm")
Subsequent period with alcohol at weekends. This coincided with a period of strenuous daily exercise (cycling).
plot.blood.pressure(bp[bp$datetime >= "2019-04-18",], "Alcohol")
plot.dates(bp[bp$datetime >= "2019-04-18",], "sys", "red")
plot.dates(bp[bp$datetime >= "2019-04-18",], "dia", "blue")
plot.dates(bp[bp$datetime >= "2019-04-18",], "pulse", "green", "bpm")